package analysis;

import utils.DateHandler;
import utils.ImageDeted;

public class BlinkDet implements IDetection {

	static ImageDeted past;
	int nOcchi, nOcchiOld = 0;
	DateHandler dh;
	boolean chiusi = false;

	public BlinkDet() {
		dh = new DateHandler();
	}

	@Override
	public ImageDeted run(ImageDeted id) {

		if (id.getNvolti() != 0) {
			nOcchi = id.getNocchi();

			if (past != null) {
				if ((nOcchiOld > nOcchi) && !chiusi) {
					chiusi = true;
					id.blinks++;
					dh.restart();
				}
				if ((chiusi) && (nOcchi > nOcchiOld)) {
					chiusi = false;
					id.closed = dh.nowEnd();
				}
			}

			nOcchiOld = id.getNocchi();
			past = id;

		}
		id.setSemaforo(-1);

		return id;
	}

}
